<?php


$con=mysql_connect('localhost','nilesh_swapen','swapen');
if(!$con)
 {
   echo "Connection Failed";
 }
$db=mysql_select_db('nilesh_swapen');
if(!$db)
 {
   echo "DB Connection Failed";
 } 

$cdate=date("Y-m-d");

$sql=mysql_query("select * from tbl_messages where type='accept' AND posteddate='$cdate' AND is_buyed='0'");
while($row=mysql_fetch_array($sql))
{
 //echo "select count(*) as cnt from tbl_messages where type='Payment Reminder' AND recieverid='".$row['recieverid']."' AND posteddate='$cdate' AND is_buyed='0'";
     $sel=mysql_query("select count(*) as cnt from tbl_messages where subject='Payment Reminder' AND recieverid='".$row['recieverid']."' AND posteddate='$cdate' AND is_buyed='0'") or mysql_error();
     $row1=mysql_fetch_array($sel);
     
     if($row1['cnt']=='0')
     {
        $accepttime = strtotime($row['bargain_accept_date']);
        $currtime = time();
        $seconds=$currtime-$accepttime;
        $hours = intval(intval($seconds) / 3600);
       if($hours >= 1)
       {
            $pmesssage_pay="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Congratulation!<br/>
                     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;You have accepted the offer.<br/>
   Please make a payment within 48 hours or the offer will become void";
           $type_pay="Payment";
           $section_pay="WS";
           $sub_pay="Payment Reminder";
            mysql_query("insert into tbl_messages(senderid,recieverid,productid,subject,message,posteddate,status,type,section,bargain_id,commision) values('0','".$row['recieverid']."','".$row['productid']."','".$sub_pay."','".$pmesssage_pay."','".date("Y-m-d")."','1','".$type_pay."','".$section_pay."','".$row['bargain_id']."','".$row['commision']."')");
       }
     }
}
?>